package preprocess;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

import trouger.dmt.JoinTableRunner;
import trouger.dmt.JoinType;
import utils.Utils;


public class AttachSalerShopToItem implements Tool{
	public static String getUniqueItemSalerShopPath(String date) {
		return Utils.rootDir + date + "/UniqueItemSalerShopDetail/";
	}
	@Override 
	public Configuration getConf() {
		return null;
	}
	
	@Override
	public void setConf(Configuration conf) {
		
	}
	/*
	 * (non-Javadoc)
	 * UserFiltered Table
	 * Path: /group/tbsc-dev/xzwang/clickprediction/$date/SalerShopDetail/

		1.CITY(所在城市)
		2.PROV(所在省份)
		3.RATE_SUM(作为卖家的信用分值，只有当等级发生变迁的时候才更新)
		4.RATE_NUM(作为买家的信用分值，只有当等级发生变迁的时候才更新)
		5.BIRTHDATE(生日)
		6.SUSPENDED(用户状态：0
		7.USER_SESSION_TIME(用户激活时间)
		8.USER_LEVERL(用户等级)
		9.USER_STYLE(收费服务类型(按位取与字段，目前定义的二进制位有
		10.USER_RANK(用户社区等级，论坛改造后没有在使用。现在还是有使用的,在商品举报的地方,有个小二专用,
		11.USER_GENDER(性别)
		12.BUYER_GOODNUM(作为买家的好评数)
		13.SELLER_GOODNUM(作为卖家的好评数)
		14.BUYER_SUM(作为买家的评价分值)
		15.BUYER_NUM(作为买家的评价次数)
		16.SELLER_SUM(作为卖家的评价分值)
		17.SELLER_NUM(作为卖家的评价次数
		18.shop[1~22]

	 	40.pv count
	 	41.click count
	 	42.saler 32位id
	 	43.saler coec
	 	44.saler ctr
	 	45.item id 32位
	 	46.item id 数字
	 	47.商品类目id
	 * */	 
	@Override
	public int run(String[] args) throws Exception {
		String output = getUniqueItemSalerShopPath(args[0]);
		String salerShopPath = DumpSalerShop.getSalerShopPath(args[0]);
		String uniqueItemPath = DumpUniqueAuctionItem.getUniqueAuctionItemPath(args[0]);
		
		System.out.println("start job AttachSalerShopToItem...");
		System.out.println("salerShopPath: " + salerShopPath);
		System.out.println("uniqueItemPath: " + uniqueItemPath);
		System.out.println("output: " + output);
		if (Utils.exitSystem(args))
			return -1;
		JoinTableRunner r = new JoinTableRunner();		

		r.addSourceTable(salerShopPath, "UTF-8", "\t");
		r.addSourceTable(uniqueItemPath, "UTF-8", "\t");
		r.addKeyGroup("1.36, 2.4");	
		r.setJoinType(JoinType.InnerJoin);
		StringBuilder columns = new StringBuilder();
		
		for (int i = 1; i <= 39; ++i) {
			columns.append("1." + String.valueOf(i) + ", ");
		}
		columns.append("2.5,2.6,1.40,1.41,1.42,2.1,2.2, 2.7");
		r.setResultFieldsEx(columns.toString());
		r.setResultTable(output);
		r.run("AttachSalerShopToItem");
		return 0;		 	
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		Utils.checkArgs(args);
		
		// TODO Auto-generated method stub
		int res = ToolRunner.run(new AttachSalerShopToItem(), args);
		System.exit(res);
	}

}
